package com.yingdong.db;

import com.yingdong.annotation.PrimeKey;
import com.yingdong.annotation.AutoIncrease;
import java.util.ArrayList;
import java.util.List;

public class ${classname?cap_first} extends DBObject{
    
    private static List<${classname?cap_first}> delList=new ArrayList<>();
   
	private static ${classname?cap_first} instance;

 <#list fields as field>  
    /**
	 * ${field.comment}
	 */
	<#if field.prim>@PrimeKey</#if>
	<#if field.autoIncrease>@AutoIncrease</#if>
    private ${field.type} ${field.name}=${field.defaultValue};
    
 </#list>  
 
<#list fields as field>  

    public ${field.type} get${field.name?cap_first}() {
	    return ${field.name};
	}
	
	public void set${field.name?cap_first}(${field.type} ${field.name}) {
		this.${field.name} = ${field.name};
		changeDBStatus();
	}
 </#list>  
 
 	public static ${classname?cap_first} getInstance() {
		if (instance == null)
			instance = new ${classname?cap_first}();
		return instance;
	}
 
    @Override
    public String getSelectByKeyString(){
    	String sql="SELECT * FROM ${tablename} WHERE 1=1<#list keys as key>  AND ${key.name}=? </#list>";
        return sql;
    }
    
    @Override
    public String getUpdateByKeyString(){
    	String sql="UPDATE  ${tablename} SET  <#list fields as field> <#if !field.prim><#if !field_has_next>${field.name}=?<#else>${field.name}=?,</#if> </#if></#list>   WHERE 1=1 <#list keys as key>  AND ${key.name}=?</#list>";
        return sql;
    }
    
    @Override
    public String getSelectAllObjectsString(){
    	String sql="SELECT * FROM ${tablename} ";
        return sql;
    }
    
    @Override
    public String getDelObjectKeyString(){
    	String sql="DELETE  FROM ${tablename} WHERE 1=1 <#list keys as key>  AND ${key.name}=?</#list>";
        return sql;
    }
    
    @Override
    public String getSelectAllObjectsKeyString(){
    	String sql="SELECT * FROM ${tablename} WHERE 1=1 <#list keys as key>  AND ${key.name}=?</#list>";
        return sql;
    }
    
    @Override
	public String getInsertString(){
	  String sql="INSERT INTO  ${tablename} (<#list fields as field><#if !field.autoIncrease><#if !field_has_next>${field.name}<#else>${field.name},</#if></#if></#list>)  VALUES(<#list fields as field><#if !field.autoIncrease><#if !field_has_next>?<#else>?,</#if></#if></#list>)";
        return sql;
	}
	
    @Override
	public String getTableName(){
	   return "${tablename}";
	}
  
}